Skip to main content

Collision Sensor

1. Write standard firmata to the device

Uploading Standard Firmata to Arduino Open Arduino IDE. File > Examples > Firmata > StandardFirmata.

Tools > Board > your board Tools > Serial Port > your port Click Upload button. if you use WSL, you need to follow this

2. Run the Collision sensor

index.tsx
import { Board, Led, Collision, render} from "edison"
import React, {useState} from "react"

const App: React.FC = () => {
const [isOn, setIsOn] = useState(false)

return (
<Board port={'/dev/tty***'} baudRate={57600}>
<Collision
pin={8}
triggered={() => setIsOn(true)}
untriggered={() => setIsOn(false)}
>
<Led
pin={13}
isOn={isOn}
/>
</Collision>
</Board>
)
}
render(<App />)

This program will blink the LED when the collision sensor is run.

3. execute the program

$ npx vite-node index.tsx 

You can use <Collision >

PropsTypeDescriptionDefault
pinnumberPin number to control currentNone
triggered?(() => void)Pin number to control currentNone
untriggered?(() => void)Pin number to control currentNone
childrenReact.ReactNodeChild components such as outbutNone